
package com.jf.cloud.product.controller.multishop;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.product.dto.StockChangeReasonLangDTO;
import com.jf.cloud.product.model.StockChangeReasonLang;
import com.jf.cloud.product.service.StockChangeReasonLangService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 出入库原因-国际化
 *
 * @author zz
 * @date 2022-06-22 17:14:22
 */
@RestController("multishopStockChangeReasonLangController")
@RequestMapping("/m/stock_change_reason_lang")
@Tag(name = "出入库原因-国际化")
public class StockChangeReasonLangController {

    @Autowired
    private StockChangeReasonLangService stockChangeReasonLangService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取出入库原因-国际化列表" , description = "分页获取出入库原因-国际化列表")
    public ServerResponseEntity<PageVO<StockChangeReasonLang>> page(@Valid PageDTO pageDTO) {
        PageVO<StockChangeReasonLang> stockChangeReasonLangPage = stockChangeReasonLangService.page(pageDTO);
        return ServerResponseEntity.success(stockChangeReasonLangPage);
    }

    @GetMapping
    @Operation(summary = "获取出入库原因-国际化" , description = "根据stockChangeReasonId获取出入库原因-国际化")
    public ServerResponseEntity<StockChangeReasonLang> getByStockChangeReasonId(@RequestParam Long stockChangeReasonId) {
        return ServerResponseEntity.success(stockChangeReasonLangService.getByStockChangeReasonId(stockChangeReasonId));
    }

    @PostMapping
    @Operation(summary = "保存出入库原因-国际化" , description = "保存出入库原因-国际化")
    public ServerResponseEntity<Void> save(@Valid @RequestBody StockChangeReasonLangDTO stockChangeReasonLangDTO) {
        StockChangeReasonLang stockChangeReasonLang = mapperFacade.map(stockChangeReasonLangDTO, StockChangeReasonLang.class);
        stockChangeReasonLang.setStockChangeReasonId(null);
        stockChangeReasonLangService.save(stockChangeReasonLang);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新出入库原因-国际化" , description = "更新出入库原因-国际化")
    public ServerResponseEntity<Void> update(@Valid @RequestBody StockChangeReasonLangDTO stockChangeReasonLangDTO) {
        StockChangeReasonLang stockChangeReasonLang = mapperFacade.map(stockChangeReasonLangDTO, StockChangeReasonLang.class);
        stockChangeReasonLangService.update(stockChangeReasonLang);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除出入库原因-国际化" , description = "根据出入库原因-国际化id删除出入库原因-国际化")
    public ServerResponseEntity<Void> delete(@RequestParam Long stockChangeReasonId) {
        stockChangeReasonLangService.deleteById(stockChangeReasonId);
        return ServerResponseEntity.success();
    }
}
